package com.joe.mp4_demo.utils;

import lombok.extern.slf4j.Slf4j;
import sun.misc.BASE64Decoder;

import java.io.File;
import java.io.FileOutputStream;
import java.util.List;
@Slf4j
public class Base {

    public static void main(String[] args) {
        //System.out.println(fileList.size());
        //doList2(fileList);
        String mp4SavePath = "C:/Users/Administrator/Desktop/test/hh40.mp4";
        FFmepgUtils.doFFe(mp4SavePath);

    }

    public static void delete(){
        File filew=new File("C:\\Users\\Administrator\\Desktop\\baimg");
        if(filew.exists()){//如果文件夹存在
            filew.delete();//删除文件夹
            log.info("删除了图片文件夹");
        }

    }

    public static void doList2(List<String> fileList){
        for (int j = 0; j < fileList.size(); j++) {
            BASE64Decoder decoder = new BASE64Decoder();
            try{
                // Base64解码
                byte[] b = decoder.decodeBuffer(fileList.get(j));
                for (int i = 0; i < b.length; ++i) {
                    if (b[i] < 0) {// 调整异常数据
                        b[i] += 256;
                    }
                }
                //将byte转换为文件
                // 生成图片路径和文件名
                File filew=new File("C:\\Users\\Administrator\\Desktop\\baimg");
                if(!filew.exists()){//如果文件夹不存在
                    filew.mkdir();//创建文件夹
                    log.info("创建了图片文件夹");
                }
                String format = String.format("%04d", j);
                String pathString ="C:\\Users\\Administrator\\Desktop\\baimg\\"+format+".jpeg";
                File file  = new File(pathString);
                FileOutputStream out = new FileOutputStream(pathString);
                out.write(b);
                out.flush();
                out.close();
            } catch (Exception e) {

            }
        }
    }
}
